<template>
    <div>
        <h2>会员信息录入</h2>
        <table class="table table-bordered">
            <tr>
                <td align="right">等级编号</td>
                <td><input type="text" v-model="state.rightsId" /></td>
            </tr>
            <tr>
                <td align="right">等级名称</td>
                <td><input type="text" v-model="state.rightsName" /></td>
            </tr>
            <tr>
                <td align="right">最大值</td>
                <td><input type="text" v-model="state.max" /></td>
            </tr>
            <tr>
                <td align="right">最小值</td>
                <td><input type="text" v-model="state.min" /></td>
            </tr>
            <tr>
                <td align="right">折扣</td>
                <td><input type="text" v-model="state.daZhe" /></td>
            </tr>
            <tr>
                <td align="right"></td>
                <td><input type="button" value="录入" @click="add" /></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
let data = reactive({
    state: {
        rightsId: "",
        rightsName: "",
        max: "",
        min: "",
        daZhe: "",
    }

})
let { state } = toRefs(data)
const add = () => {
    if(state.value.rightsId==""){
        alert("等级编号不能为空")
        return;
    }
    if(state.value.rightsName==""){
        alert("等级名称不能为空")
        return;
    }
    if(state.value.max==""){
        alert("最大值不能为空")
        return;
    }
    if(state.value.min==""){
        alert("最小值不能为空")
        return;
    }
    if(state.value.daZhe==""){
        alert("折扣不能为空")
        return;
    }
    let obj = {
        rightsId: state.value.rightsId,
        rightsName: state.value.rightsName,
        max: state.value.max,
        min: state.value.min,
        daZhe: state.value.daZhe,
    }
    axios({
        url: '/api/Member/AddRights',
        method: 'post',
        data: obj
    })
        .then(res => {
            console.log(res)
            if (res.data.data == 1) {
                alert("添加成功")
                router.push("/rlist")
            }
            if (res.data.data == -1) {
                alert("名称不能重复")
                return
            }
        })
        .catch(err => {
            console.log(err)
        })
}
</script>

<style scoped></style>